#include "stdio.h"
#include "string.h"
#include "stdlib.h"

typedef struct str_1
{
    char name[128];
    char sex[64];
    int age;
    int id;
    int sco;
} str_1;

str_1 hqyj_24071[] =
    {
        {.id = 1, .name = "唐三", .age = 18, .sco = 100, .sex = "男"},
        {.id = 2, .name = "萧炎", .age = 18, .sco = 99, .sex = "男"},
        {.id = 3, .name = "叶晨", .age = 18, .sco = 99, .sex = "男"},
        {.id = 4, .name = "小舞", .age = 18, .sco = 99, .sex = "女"},
        {.id = 5, .name = "萧熏儿", .age = 18, .sco = 99, .sex = "女"},
        {.id = 6, .name = "柳如烟", .age = 18, .sco = 99, .sex = "女"},
};

int main(int argc, char const *argv[])
{
    // 打开文件
    FILE *fp = fopen("hqyj.txt", "w");
    if (fp == NULL)
    {
        printf("无法打开文件！");
        return 1;
    }

    // 将学生信息写入文件
    for (size_t i = 0; i < strlen(hqyj_24071->name); i++)
    {
        fprintf(fp, "学号：%d\t名字：%s\t年龄：%d\t成绩：%d\t性别：%s\n",
                hqyj_24071[i].id,hqyj_24071[i].name,hqyj_24071[i].age, hqyj_24071[i].sco, hqyj_24071[i].sex);
    }

    // 关闭文件
    fclose(fp);

    return 0;
}
